 

function dangerRecords($rootScope, $scope, $http, ngDialog, paFetchService, ngDialogConfirm) {
  'ngInject';
  this.queryData = {};
  this.paginationQuery = function() {};

  // 分页
  this.paginationData = {
    pageNum: 1,
    pageSize: 10,
    total: 4,
  }

  this.records = [
    {
      id: '2016110401',
      creator: '唐博博',
      createTime: '2016-11-04 11:32',
      area: '临时用电区域',
      address: '一标ZD-200桩',
      result: '合格',
    },
    {
      id: '2016110402',
      creator: '唐博博',
      createTime: '2016-11-04 11:32',
      area: '临时用电区域',
      address: '一标ZD-200桩',
      result: '不合格',
      remark: '配电箱距离地面距离不合要求'
    },
  ]

  this.topChecked = false;
  this.toggleAll = () => {
    // if (this.topChecked) {
      this.dangerManagementList.forEach((item) => {
        item.checked = this.topChecked
      })
    // }
  }

  this.printQrCode = () => {
    let selectedItems = this._getSelectedItems();
    if (!selectedItems.length) {
      layer.alert('请选择危险源');
      return;
    }
    $scope.selectedItems = selectedItems;
    ngDialog.openConfirm({
      template: 'dangerManagementQrCode',
      className: 'ngdialog-theme-default pa-confirm-theme',
      scope: $scope,
      controllerAs: 'vm',
      controller: function($scope) {
        'ngInject';
        this.selectedItems = selectedItems;
        console.log(selectedItems)
        this.print = () => {
          $('.qr-print').print();
        }

        this.getQrCodeSrc = (item) => {
          let qrContent = encodeURIComponent(`#/dangerSource/${item.id}`);
          let requestUrlStr = 
          `${$scope.serverContext}/api/qr?size=160&code=${qrContent}`;
          return requestUrlStr;
        }
      },
    })
  }

  this._getSelectedItems = () => {
    let res = [];
    this.dangerManagementList.forEach((item) => {
      if (item.checked) {
        res.push(item);
      }
    })
    return res;
  }

  // 重置
  this.reset = () => {
    this.queryData = {
    	queryType: 0,
      bidId: $rootScope.activeBid.bidId,
    };
  }

  // 查询
  this.query = (param) => {
	  this.paginationQuery();
  }

  this.checkDetail = (detail) => {
    let _this = this;
    ngDialog.open({
      template: 'recordDetail',
      className: 'ngdialog-theme-default pa-special-check-item-list-theme',
      controllerAs: 'detail',
      scope: $scope,
      controller: function trainClarifyCtrl($scope, $http) {
        'ngInject';
        this.model = detail;
        this.save = () => {
          $scope.closeThisDialog();
        }

      }
    });
  }

  this.deleteDetail = ($index) => {
    ngDialogConfirm
      .confirm()
      .then(() => {
        this.records.splice($index, 1);
      })
  }

}

export default dangerRecords;